/*
  esp8266
  NodeMCU 网页请求
  2021-09-14
*/

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

const char * URL = "http://www.taichi-maker.com/homepage/iot-development/iot-dev-reference/esp8266-c-plus-plus-reference/http-client-secure/wificlientsecure/";
#define ssid "TPLee" //"TPLeeSZ"
#define pwd  "6515304*eeL" //"2021#@Lee.com"

void setup() {
  Serial.begin(9600);

  WiFi.mode(WIFI_STA); // 工作模式为无线终端
  WiFi.begin(ssid, pwd); // 连接wifi
  
  while (WiFi.status() != WL_CONNECTED) // 等待连接
  {
    delay(1000);
    Serial.print(".");
  }
  Serial.println();
  Serial.println("Wifi Connected");
  
  httpClientRequest();
}

void httpClientRequest()
{
  HTTPClient client;
  WiFiClient httpClient;
  client.begin(httpClient, URL);
  Serial.printf("URL: %s\n\n", URL);

  int httpCode = client.GET(); // 启动连接发送HTTP请求
  Serial.printf("Send GET request to %s resp %d\n\n", URL, httpCode);

  if (httpCode == HTTP_CODE_OK) // 返回成功
  {
    String resp = client.getString();
    Serial.printf("Server response %s\n\n", resp);
  }

  client.end();// 关闭服务器连接
  httpClient.stop();
}

void loop() {
  // put your main code here, to run repeatedly:

}
